gtkstack: fix null pointer dereference
authorHugo Lefeuvre <hle@debian.org>
Wed, 26 Sep 2018 20:59:59 +0000 (16:59 -0400)
committerHugo Lefeuvre <hle@debian.org>
Thu, 27 Sep 2018 13:53:22 +0000 (09:53 -0400)
The gtk_stack_snapshot_slide() function dereferences the
last_visible_child pointer without proper != NULL ckeck. This might
result in NULL pointer dereference and crash if last_visible_child is
invalid.

Add a != NULL check before dereferencing the pointer.

gtk/gtkstack.c

index a3d36a86033b8a527bdfe2e07b3d973e8dc5e19f..f74894b8e10511fe4fd7d21b8e1100be8250dca8 100644 (file)
@@ -1910,11 +1910,14 @@ gtk_stack_snapshot_slide (GtkWidget   *widget,
           break;
         }
 
-      if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_END &&
-          priv->last_visible_widget_height > height)
-        y -= priv->last_visible_widget_height - height;
-      else if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_CENTER)
-        y -= (priv->last_visible_widget_height - height) / 2;
+      if (priv->last_visible_child != NULL)
+        {
+          if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_END &&
+              priv->last_visible_widget_height > height)
+            y -= priv->last_visible_widget_height - height;
+          else if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_CENTER)
+            y -= (priv->last_visible_widget_height - height) / 2;
+        }
 
       gtk_snapshot_offset (snapshot, x, y);
       gtk_snapshot_append_node (snapshot, priv->last_visible_node);